package com.zyy.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 类描述
 * @Author: zyy
 * @Date: 2023/08/03 21:55
 */
public class BoxFactory {
    private Map<String, AbstractBox> map;

    //私有化构造方法
    private BoxFactory() {
        map = new HashMap<>();
        IBox iBox = new IBox();
        LBox lBox = new LBox();
        OBox oBox = new OBox();
        map.put("I", iBox);
        map.put("L", lBox);
        map.put("O", oBox);
    }

    //单例模式，静态内部类方式
    private static class SingletonHolder {
        private static final BoxFactory INSTANCE = new BoxFactory();
    }

    public static BoxFactory getInstance() {
        return SingletonHolder.INSTANCE;
    }
    //根据图形名称获取图形对象
    public AbstractBox getShape(String name) {
        return map.get(name);
    }

}
